package com.laihuichuxing.mq.consumerRocket;


import com.laihuichuxing.order.dao.DriverOrderDao;
import com.laihuichuxing.pool.DriverLbs4MongoPool;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.starter.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.starter.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Description: 司机定位消费者
 *
 * @author YangGuang
 * @since: 1.0
 * Create Date Time: 2018/10/9 10:08
 * Update Date Time:
 */
@Slf4j
@Service
@RocketMQMessageListener(topic = "listenPositionTopic", consumerGroup = "${spring.rocketmq.listenPositionGroup}")
public class DriverPositionRConsumer implements RocketMQListener<Map> {

    @Autowired
    private DriverOrderDao driverOrderDao;

    @Autowired
    private DriverLbs4MongoPool driverLbs4MongoPool;


    /**
     * Description: 司机听单后定位topic
     *
     * @param map
     * @author: YangGuang
     * Create Date Time: 2018/10/10 17:47
     * Update Date Time:
     */
    @Override
    public void onMessage(Map map) {
        try {
            // 查询接单状态,如果已接单,忽略
            String acceptFlag = driverOrderDao.selectAcceptFlag(map.get("mobile").toString());
            if ("0".equals(acceptFlag)) {
                driverLbs4MongoPool.offer(map.get("longitude").toString(),map.get("latitude").toString()
                        ,map.get("mobile").toString(),map.get("cityCode").toString());
            }
        } catch (Exception e) {
            log.error("听单实时位置保存到mongodb异常,异常信息:{}", e.toString(), e);
        }
    }
}